home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / h_eq_int.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  129 lines

  1. ; $Id: h_eq_int.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1989-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. pro h_eq_int, image    ;Histogram equalize color tables from image
  8. ;+
  9. ; NAME:
  10. ;    H_EQ_INT
  11. ;
  12. ; PURPOSE:
  13. ;    Interactively histogram-equalize the color tables of an image
  14. ;    or a region of the display.  By moving the cursor across
  15. ;    the screen, the amount of histogram equalization is varied.
  16. ;
  17. ; CATEGORY:
  18. ;    Image processing.
  19. ;
  20. ; CALLING SEQUENCE:
  21. ;    H_EQ_INT, Image        ;To histogram equalize from an image.
  22. ;    H_EQ_INT        ;To histogram equalize from a region.
  23. ;
  24. ; INPUTS:
  25. ;    Image:    The image whose histogram is to be used in determining
  26. ;        the new color tables.  If this value is omitted, the user 
  27. ;        is prompted to mark the diagonal corners of a region of the 
  28. ;        display.
  29. ;
  30. ;        Image MUST be a byte image, scaled the same way as
  31. ;        the image loaded to the display.
  32. ;
  33. ; OUTPUTS:
  34. ;    No explicit outputs.  The result is applied to the current color
  35. ;    tables.
  36. ;
  37. ; COMMON BLOCKS:
  38. ;    COLORS:    The IDL color table common block.
  39. ;
  40. ; SIDE EFFECTS:
  41. ;    The current color table is modified.
  42. ;
  43. ; RESTRICTIONS:
  44. ;    If a parameter is supplied, it is assumed to be an image that
  45. ;    was just displayed.
  46. ;
  47. ; PROCEDURE:
  48. ;    Either the image parameter or the region of the display marked by
  49. ;    the user is used to obtain a pixel-distribution histogram.  The
  50. ;    cumulative integral is taken and scaled.  This function is applied
  51. ;    to the current color tables.
  52. ;
  53. ;    A window is created and the histogram equalization function is 
  54. ;    plotted.
  55. ;
  56. ;    A linear ramp is overplotted.  Move the cursor from left
  57. ;    to right to vary the amount of histogram equalization applied to the 
  58. ;    color tables from 0 to 100%.  Press the right mouse button to exit.
  59. ;
  60. ; MODIFICATION HISTORY:
  61. ;    DMS, November, 1989, written.
  62. ;    AB, 21 September 1992,renamed from HIST_EQUAL_INT to H_EQ_INT to
  63. ;        avoid DOS filename limitations. HIST_EQUAL_INT is still
  64. ;        available as a wrapper to this routine under operating
  65. ;        systems that can handle longer file names.
  66. ;    JWG, 14 December 1992,routine did not restore font.
  67. ;-
  68.  
  69. common colors,r,g,b,cur_red,cur_green,cur_blue
  70.  
  71. on_error,2                      ;Return to caller if an error occurs
  72. nc = !d.table_size    ;# of colors in device
  73. if nc eq 0 then message, 'Device has static color tables, Can''t adjust'
  74. if n_elements(image) gt 0 then h = histogram(image) $
  75.     else begin
  76.     print,'Mark opposite corners of area of interest:'
  77.     cursor,x,y,/dev,1    ;one corner
  78.     wait,.5            ;Necessary for fast machines
  79.     cursor,x1,y1,/dev,1
  80.     x0 = x < x1
  81.     y0 = y < y1
  82.     x1 = x > x1
  83.     y1 = y > y1
  84.     h = histogram(tvrd(x0,y0,x1-x0+1, y1-y0+1))
  85.     endelse
  86. h[0] = 0        ;For 0 backgrounds
  87. for i=1,n_elements(h)-1 do h[i] = h[i]+h[i-1]
  88. h = long(bytscl(h, top = nc-1))
  89.  
  90. old_window = !d.window
  91. window,xs=400, ys=300,title='Histogram Equalization',/free
  92. plot,h
  93. oplot,[0,nc-1],[0,nc-1]
  94. tvcrs,.5,.5,/norm
  95.  
  96. !err = 0
  97. fact = 0.0
  98. oldy = findgen(nc)
  99. oldfact = 0.0
  100. x = findgen(nc)
  101. if n_elements(r) le 0 then begin    ;color tables defined?
  102.     r=indgen(nc) & g=r & b=r & endif
  103. oldfont = !p.font
  104. !p.font = 0
  105. oldfacts = string(oldfact,format='(f5.3)')+' equalized'
  106. xyouts,.1,.95,/norm,oldfacts
  107.  
  108. while !err ne 4 do begin
  109.     cursor,xx,yy,2        ;wait for movement
  110.     fact = float(xx)/nc < 1.0 > 0.0
  111.     if fact ne oldfact then begin
  112. ;        oplot,x,oldy,psym=3,color=0    ;Erase old
  113.         oldy = long(fact * h + (1.-fact) * x)
  114. ;        oplot,x,oldy,psym=3
  115.         cur_red = r[oldy] & cur_green = g[oldy] & cur_blue = b[oldy]
  116.         tvlct,cur_red, cur_green, cur_blue
  117.         xyouts,.1,.95,/norm, oldfacts, col=0
  118.         oldfacts = string(oldfact,format='(f5.3)')+' equalized'
  119.         xyouts,.1,.95,/norm,oldfacts
  120.         oldfact = fact
  121.         endif
  122.     endwhile
  123. wdelete
  124. !p.font = oldfont
  125. wset,old_window
  126. return
  127. end
  128.  
  129.